package utils;

import java.util.HashMap;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

public class SmsUtil {
	
	public static String serverIp = "app.cloopen.com";
    //请求端口
	public static String serverPort = "8883";
    //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
	public static String accountSId = "8a216da86715511501671f4e20e10767";
	public static String accountToken = "b88b14ba73264692a3dce2bcf3ecc5ec";
    //请使用管理控制台中已创建应用的APPID
	public static String appId = "8a216da86715511501671f4e2127076d";
    
	
	public static boolean sendSms(String to, String templateId, String[] datas){
		CCPRestSmsSDK sdk = new CCPRestSmsSDK();
	    sdk.init(serverIp, serverPort);
	    sdk.setAccount(accountSId, accountToken);
	    sdk.setAppId(appId);
	    sdk.setBodyType(BodyType.Type_JSON);
	    
	  //请求发送短信
	    HashMap<String, Object> result = sdk.sendTemplateSMS(to,templateId,datas);
	    
	    if("000000".equals(result.get("statusCode"))){
	    	System.out.println("短信发送成功");
	        return true;
	    }else{
	        //异常返回输出错误码和错误信息
	        System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
	    }
		return false;
	}
}
